package com.mininglamp.main;

import com.mininglamp.mode.Input;
import org.drools.core.event.DefaultAgendaEventListener;
import org.kie.api.KieServices;
import org.kie.api.event.rule.AfterMatchFiredEvent;
import org.kie.api.event.rule.BeforeMatchFiredEvent;
import org.kie.api.runtime.KieContainer;
import org.kie.api.runtime.KieSession;
import org.kie.api.runtime.StatelessKieSession;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by zhouhuiyu on 17/9/10.
 */
public class TestOrgSessionlessMain {

    protected static final Logger logger          = LoggerFactory.getLogger( TestOrgSessionlessMain.class);
    public static void main(String[] args) {

        KieServices ks = KieServices.Factory.get();
        //KieContainer kContainer = ks.newKieContainer(ks.newReleaseId("org.slf4j", "slf4j-api", "1.5.6"));

        KieContainer kContainer = ks.getKieClasspathContainer();


        StatelessKieSession kSession = kContainer.newStatelessKieSession("test002");
        kSession.addEventListener(new DefaultAgendaEventListener() {
            public void afterMatchFired(AfterMatchFiredEvent event) {
                super.afterMatchFired( event );
                System.out.println( event + " ========zhy after ====");
            }

            @Override
            public void beforeMatchFired(BeforeMatchFiredEvent event) {
                super.beforeMatchFired(event);
                System.out.println();
                System.out.println( event + " ========zhy before ====");
            }
        });

        Input input = new Input("刘磊", "男", "18", "湖南", 1.69D, 1500);

        kSession.setGlobal("input", input);

        kSession.execute(input);

        String name = ((Input)kSession.getGlobals().get("input")).getName();
        logger.info(name);

        List<Input> inputs = new ArrayList<Input>();
        for (int i =0; i < 1; i++){
            Input input1 = new Input("刘磊", "男", "18", "湖南", 1.69D, 1500);
            inputs.add(input1);
        }

        kSession.execute(inputs);

    }

}
